package com.example.demo.jucConcurrent.FutureTask详解;

import java.util.concurrent.*;

/**
 * Future+ExecutorService
 *
 */
public class FutureDemo {
    public static void main(String[] args) {

        ExecutorService executorService = Executors.newCachedThreadPool();
        Future future = executorService.submit(new Callable<Object>() {
            @Override
            public Object call() {
                long start = System.currentTimeMillis();
                while (true) {
                    long current = System.currentTimeMillis();
                    if ((current - start) > 1000) {
                        return 1;
                    }
                }

            }
        });

        try {
            Integer  result = (Integer) future.get();
            System.out.println("result = " + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
